
--<BLK>--
	select	
a.AccountKey,
case when a.ScenarioKey = 1 then 'A' else 'B' end as ScenarionInd,
sum(b.Amount) as Amount
	into	
dbo.NewTable
	from	  
dbo.FactFinance a left outer join FactFinance b 
	on		
a.AccountKey = b.AccountKey
	where	
a.AccountKey in 
(select AccountKey from FactFinance group by AccountKey)
	--<X>--
	group by	
 a.AccountKey,case when a.ScenarioKey = 1 then 'A' else 'B' end
	having	
sum(b.Amount) > 1000000000
	order by	
AccountKey
--</BLK>--



--<BLK>--
select 
into
from
where
group by 
having
order by
--</BLK>--
